$(function () {

    var agentUserId = $("#agentUserId").val();

    $('body').on('click','#tongguo', function () {
        aduitAgentUser(true);
    }).on('click','#bohui',function () {
        aduitAgentUser(false);
    })

    /**
     *
     * @param flag  true：通过，false：驳回
     */
    function aduitAgentUser(flag) {
        var params = {"agentUserId": agentUserId,"flag": flag};
        if(!flag){
            parent.layer.open({
                type: 1,
                area: ['500px','300px'],
                skin: 'layui-layer-demo',
                title: '<strong>审核-驳回</strong>',
                content: '<div class="m-t m-r m-l m-b" style="text-align: center"><textarea style="width:450px;height: 150px; resize: none;" id="rejectedCause"></textarea></div>',
                btn: '确定',
                yes: function(index, layero) {
                    var rejectedCause = layero.find('#rejectedCause').val();
                    params.rejectedCause = rejectedCause;
                    $.ajax({
                        url:baseloaction+"/admin/agent/user/auditAgentUser",
                        type:"post",
                        data: params,
                        dataType:"json",
                        success:function (result) {
                            icModale(0,result.message);
                            if (result.success) {
                                parent.layer.close(index);
                                window.location.href = baseloaction+"/admin/agent/user/queryAgentUserList";
                            }
                        },
                        error: function () {
                            icModale(0,"系统繁忙，请稍后重试");
                        }
                    });
                }
            });
        }else{
            $.ajax({
                url:baseloaction+"/admin/agent/user/auditAgentUser",
                type:"post",
                data: params,
                dataType:"json",
                success:function (result) {
                    icModale(0,result.message);
                    if (result.success) {
                        window.location.href = baseloaction+"/admin/agent/user/queryAgentUserList";
                    }
                },
                error: function () {
                    icModale(0,"系统繁忙，请稍后重试");
                }
            });
        }
    }
});